const wp = require('@cypress/webpack-preprocessor')

module.exports = (on, config) => {
  const options = {
    webpackOptions: require('../../tools/webpack/webpack.cypress'),
  }
  require('@cypress/code-coverage/task')(on, config)

  on('before:browser:launch', (browser = {}, launchOptions) => {
    if (browser.name === 'chrome' || browser.name === 'chromium' || browser.name === 'canary') {
      launchOptions.args.push('--auto-open-devtools-for-tabs')

      return launchOptions
    }
    return launchOptions
  })
  on('file:preprocessor', wp(options))
  return config
}
